<template>
  <div class="app-container">
    <el-card shadow="never">
      <el-form label-width="auto" style="max-width: 600px">
        <el-form-item label="頁碼">
          <el-input v-model="page" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loading" @click="onSubmit">
            按頁碼讀取一條訪客並發送全部場所封包
          </el-button>
          <el-button type="success" :loading="loading2" @click="downloadAllLocationMessage">
            提取1000筆訪客及其位置組合封包
          </el-button>
        </el-form-item>
        <el-form-item label="定位封包JSON">
          <el-input v-model="messages" type="textarea" :autosize="{ minRows: 2, maxRows: 10 }" />
          ***返回的是一個數據，主題和消息使用@進行分隔，請自行使用工具進行處理
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { ref } from "vue";
defineOptions({
  name: "Customer",
  inheritAttrs: false,
});

const { t } = useI18n();
const messages = ref("");
import MockAPI from "@/api/mock";
const loading = ref(false);
const loading2 = ref(false);
const page = ref(1);

function onSubmit() {
  loading.value = true;
  MockAPI.sendLocationMessage(page.value)
    .then((data) => {
      ElMessage.info(data.data["message"]);
    })
    .finally(() => {
      loading.value = false;
    });
}

function downloadAllLocationMessage() {
  loading2.value = true;
  MockAPI.downloadAllLocationMessage()
    .then((data) => {
      messages.value = JSON.stringify(data);
    })
    .finally(() => {
      loading2.value = false;
    });
}
</script>

<style scoped>
.scrollbar-demo-item {
  margin-bottom: 10px;
  border-bottom: 1px solid #eee;
}
</style>
